package com.star.common.sms.factory;


import com.star.common.sms.service.SmsClient;

import java.util.Map;
import java.util.Objects;

/**
 * 短信工厂
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/6/25 14:38
 */
public class SmsFactory {
    private final Map<String, SmsClient> smsClientMap;

    public SmsFactory(Map<String, SmsClient> smsClientMap) {
        this.smsClientMap = smsClientMap;
    }

    /**
     * 生产短信发送方
     *
     * @param provider 短信类型，
     *                 See Also: com.changzhi.middleware.sms.enums.SmsTypeEnum
     * @return
     */
    public SmsClient buildSmsClient(String provider) {
        SmsClient smsClient = smsClientMap.get(provider);
        if (Objects.isNull(smsClient)) {
            throw new RuntimeException("当前的【" + provider + "】的对应的yml配置为空，或者【" + provider + "】类型不存在");
        }
        return smsClient;
    }
}
